home *** CD-ROM | disk | FTP | other *** search
/ Univers Interactif 3 / INTERACTIF.BIN / mac / Planete.net / Internet Confirmés_Vrac / NetAgent.sea / src / agentd.c < prev    next >
C/C++ Source or Header  |  1992-06-15  |  2KB  |  82 lines

  1. /*
  2. This is an unsupported product. It was developed as part of a study at Ostfold
  3. Regional College, Norway in the spring of 1992.
  4.  
  5. You use this software at your own risk. Neither the authors nor the Ostfold
  6. Regional College nor any other person or organization except yourself is
  7. responsible for any damage or loss of data derived from the use of this
  8. software. You may distribute this software freely as long as it is in its
  9. original form and all of its files are included. If you make any changes to any
  10. part of this software or the files distributed with it, please state so and do
  11. NOT distribute it under its original name.
  12. */
  13.  
  14. /* 
  15. This module is the main module of the agentd program.
  16. */
  17.  
  18. #include <stdio.h>
  19. #include <string.h>
  20. #include <sys/types.h>
  21. #include <sys/socket.h>
  22. #include <netinet/in.h>
  23. #include <netdb.h>
  24. #include <fcntl.h>
  25. #include <sys/wait.h>
  26. #include "nntp_tcp.h"
  27. #include "server.h"
  28.  
  29. /*
  30. -----------------------------------------------------------------------------
  31. Function name: main()
  32. -----------------------------------------------------------------------------
  33. Parameters:    int argc        Number of arguments.
  34.         char *argv        List of arguments.
  35. Return value:    none
  36. Called by:    none
  37. Calls:        tcp_connect_listen(), do_server()
  38. Description:    This function runs in an infinitive loop listening to a port
  39.         and starting up the server when connection has been
  40.         established.
  41. -----------------------------------------------------------------------------
  42. */
  43.  
  44. main( argc, argv)
  45. int argc;
  46. char *argv[];
  47. {
  48.     int s, t, f, i, port;
  49.     struct sockaddr_in i_sa;
  50.     char command[80];
  51.  
  52.         myname = argv[0];
  53.  
  54.         if(argc != 2) {
  55.                 fprintf(stderr, "Usage: %s port\n", myname);
  56.                 exit(1);
  57.         }
  58.     port = atoi(argv[1]);
  59.     s = tcp_connect_listen(port);
  60.  
  61.     while(1) {
  62.         i = sizeof(i_sa);
  63.         if(( t = accept( s, &i_sa, &i)) < 0) {
  64.             perror("accept");
  65.             exit(1);
  66.         }
  67.  
  68.         if((f = fork()) < 0 ) {
  69.             perror("fork");
  70.             exit(1);
  71.         }
  72.  
  73.         if( f == 0 )
  74.             do_server(t);
  75.         else
  76.             close(t);
  77.  
  78.         while(wait3(NULL, WNOHANG, NULL) != 0) {
  79.         }
  80.     }
  81. }
  82.